/**
 * 
 */
package com.jysz.certificate.persistence.model.system;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.jysz.certificate.persistence.enums.RegionEnum;
import com.jysz.webcore.ssh.entity.AbstractBaseEntity;

/**
 * 行政区划
 * 
 * @author <a href="mailto:javaengine@outlook.com">Kaca Rich</a>
 *
 */
@Entity
@Table(name = "sys_region_")
@org.hibernate.annotations.Entity
public class Region extends AbstractBaseEntity<Long>{

	private static final long serialVersionUID = 1L;

	private String name;
	private RegionEnum type;
	private Region parent;
	private List<Region> childs;

	
	@Column(name = "_name",columnDefinition="varchar(255)")
	public String getName() {
		return name;
	}
	 
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name = "_type",columnDefinition="int(11)")
	public RegionEnum getType() {
		return type;
	}
	
	public void setType(RegionEnum type) {
		this.type = type;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)  
	@JoinColumn(name = "_parent_id",columnDefinition="bigint(20)") 
	public Region getParent() {
		return parent;
	}
	public void setParent(Region parent) {
		this.parent = parent;
	}
	
	@OneToMany(targetEntity = Region.class, cascade = { CascadeType.ALL }, mappedBy = "parent")  
	@Fetch(FetchMode.SUBSELECT) 
	public List<Region> getChilds() {
		return childs;
	}

	public void setChilds(List<Region> childs) {
		this.childs = childs;
	}

	/**begin properties column constan**/
	public static final String COLUMN_CODE = "code";
	public static final String COLUMN_PARENT = "parent";
	public static final String COLUMN_NAME = "name";
	public static final String COLUMN_TYPE = "type";
	/**end properties column constan**/

	

	
}
